<template>
    <div>
        <!--      搜索  创建-->
        <el-form :inline="true" :model="form" class="demo-form-inline">
            <!-- <el-form-item>

                <el-select style="width: 280px" v-model="form.state" placeholder="请选择类别">
                    <el-option lable="男" value="0">志愿者</el-option>
                    <el-option lable="女" value="1">志愿组织</el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="query">搜索</el-button>
            </el-form-item> -->
            <el-form-item>
                <el-button type="success" @click="createvolunteer">志愿者注册</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="createorganization">志愿组织注册</el-button>
            </el-form-item>
        </el-form>
        <!--           列表-->
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="志愿者" name="first">
                <el-table display="none" :data="tableData" border>
            <!-- <template scope="scope"> -->
                <el-table-column
                    prop="name"
                    label="姓名"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="sex"
                    label="性别"
                    align="center">
                    <template slot-scope = "scope">
                        <span v-if="scope.row.sex == '0'">男</span>
                        <span v-if="scope.row.sex == '1'">女</span>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="tel"
                    label="联系电话"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="status"
                    label="状态"
                    align="center">
                    <template slot-scope = "scope">
                        <span v-if="scope.row.status == '0'">未审核</span>
                        <span v-if="scope.row.status == '1'">审核通过</span>
                        <span v-if="scope.row.status == '2'">审核失败</span>
                    </template>
                </el-table-column>

            <!-- </template> -->
            <el-table-column
                    fixed="right"
                    label="操作"
                    align="center">
                <template slot-scope="scope">
                    <el-button
                            type="success"
                            size="mini"
                            @click="handleEdit(scope.row)">编辑
                    </el-button>
                    <el-button
                            type="danger"
                            size="mini"
                            @click="handleDelete(scope.row)" >删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
            </el-tab-pane>
            <el-tab-pane label="志愿组织" name="second">
                <el-table display="none" :data="tableData" border>
            <!-- <template scope="scope"> -->
                <el-table-column
                    prop="organization_name"
                    label="组织名称"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="organization_Contacts"
                    label="组织联系人"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="organization_tel"
                    label="联系电话"
                    align="center">
                </el-table-column>
                <el-table-column
                    prop="status"
                    label="状态"
                    align="center">
                    <template slot-scope = "scope">
                        <span v-if="scope.row.status == '0'">未审核</span>
                        <span v-if="scope.row.status == '1'">已通过</span>
                        <span v-if="scope.row.status == '2'">已退回</span>
                    </template>
                </el-table-column>
            <!-- </template> -->
            <el-table-column
                    fixed="right"
                    label="操作"
                    align="center">
                <template slot-scope="scope">
                    <el-button
                            type="success"
                            size="mini"
                            @click="organizationEdit(scope.row)">编辑
                    </el-button>
                    <el-button
                            type="danger"
                            size="mini"
                            @click="handleDelete(scope.row)" >删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
            </el-tab-pane>
        </el-tabs>

<!--        分页-->
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNo"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next"
                :total="totalRecord" class="text-center mt10">
        </el-pagination>
<!--        创建志愿者弹出框-->
        <el-dialog title="创建志愿者信息" :visible.sync="dialogFormVisible">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
                <el-form-item label="姓名" prop="name">
                    <div style="width: 320px">
                        <el-input v-model="ruleForm.name"></el-input>
                    </div>
                </el-form-item>
               <!--  <el-form-item label="账号" prop="login_name">
                    <div style="width: 320px">
                        <el-input v-model="ruleForm.login_name"></el-input>
                    </div>
                </el-form-item> -->
                <!-- <el-form-item label="性别" prop="sex">
                    <div style="width: 320px">
                        <el-input v-model="ruleForm.sex"></el-input>
                    </div>
                </el-form-item> -->
                <el-form-item label="性别" prop="sex">
                    <el-select style="width: 320px" v-model="ruleForm.sex" placeholder="请选择">
                        <el-option label="男" value="0">男</el-option>
                        <el-option label="女" value="1">女</el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="家庭住址" prop="address">
                    <div style="width: 320px">
                        <el-input v-model="ruleForm.address"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="政治面貌" prop="outlook">
                    <div style="width: 320px">
                        <el-input v-model="ruleForm.outlook"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="联系电话" prop="tel">
                    <div style="width: 320px">
                        <el-input v-model="ruleForm.tel"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="爱好" prop="hobby">
                    <div style="width: 320px">
                        <el-input v-model="ruleForm.hobby"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="服务意向" prop="intention">
                    <div style="width: 320px">
                        <el-input v-model="ruleForm.intention"></el-input>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="sure">确 定</el-button>
            </div>
        </el-dialog>

<!--        修改志愿者弹出框-->
        <el-dialog title="修改志愿者信息" :visible.sync="dialogFormVisibleEdit">
            <el-form :model="ruleFormEdit" :rules="rulesEdit" ref="ruleForm" label-width="180px" class="demo-ruleForm">
                <el-form-item label="姓名" prop="name">
                    <div style="width: 320px">
                        <el-input v-model="ruleFormEdit.name"></el-input>
                    </div>
                </el-form-item>
               <!--  <el-form-item label="账号" prop="login_name">q
                    <div style="width: 320px">
                        <el-input v-model="ruleFormEdit.login_name"></el-input>
                    </div>
                </el-form-item> -->
                <!-- <el-form-item label="性别" prop="sex">
                    <el-select style="width: 320px" v-model="ruleFormEdit.sex" placeholder="请选择">
                            <el-option lable="男" value="0">男</el-option>
                            <el-option lable="女" value="1">女</el-option>
                        </el-select>
                </el-form-item> -->
                <el-form-item label="性别" prop="sex">
                    <el-select style="width: 320px" v-model="ruleFormEdit.sex" placeholder="请选择" >
                        <el-option label="男" value="0">男</el-option>
                        <el-option label="女" value="1">女</el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="家庭住址" prop="address">
                    <div style="width: 320px">
                        <el-input v-model="ruleFormEdit.address"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="政治面貌" prop="outlook">
                    <div style="width: 320px">
                        <el-input v-model="ruleFormEdit.outlook"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="联系电话" prop="tel">
                    <div style="width: 320px">
                        <el-input v-model="ruleFormEdit.tel"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="爱好" prop="hobby">
                    <div style="width: 320px">
                        <el-input v-model="ruleFormEdit.hobby"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="服务意向" prop="intention">
                    <div style="width: 320px">
                        <el-input v-model="ruleFormEdit.intention"></el-input>
                    </div>
                </el-form-item>
                <!--<el-form-item label="失败原因" prop="reason">
                    <div style="width: 320px">
                        <el-input v-model="ruleFormEdit.reason"></el-input>
                    </div>
                </el-form-item>-->
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisibleEdit = false">取 消</el-button>
                <el-button type="primary" @click="yes">确 定</el-button>
            </div>
        </el-dialog>

<!--        创建志愿组织弹出框-->
        <el-dialog title="创建志愿组织信息" :visible.sync="createorganizationVisible">
            <el-form :model="organizationForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
                <!-- <el-form-item label="志愿组织用户名" prop="admin">
                    <div style="width: 320px">
                        <el-input v-model="organizationForm.admin"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="登录密码" prop="password">
                    <div style="width: 320px">
                        <el-input v-model="organizationForm.password"></el-input>
                    </div>
                </el-form-item> -->
                <el-form-item label="组织名称" prop="organization_name">
                    <div style="width: 320px">
                        <el-input v-model="organizationForm.organization_name"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="组织类型" prop="organization_type">
                    <div style="width: 320px">
                        <el-input v-model="organizationForm.organization_type"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="组织联系人" prop="organization_Contacts">
                    <div style="width: 320px">
                        <el-input v-model="organizationForm.organization_Contacts"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="组织联系电话" prop="organization_tel">
                    <div style="width: 320px">
                        <el-input v-model="organizationForm.organization_tel"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="组织性质" prop="organization_objective">
                    <div style="width: 320px">
                        <el-input v-model="organizationForm.organization_objective"></el-input>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="createorganizationVisible = false">取 消</el-button>
                <el-button type="primary" @click="sure1">确 定</el-button>
            </div>
        </el-dialog>

        <!--        修改志愿组织弹出框-->
        <el-dialog title="修改志愿组织信息" :visible.sync="updateorganizationVisible">
            <el-form :model="updateorganizationForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
                <!-- <el-form-item label="志愿组织用户名" prop="admin">
                    <div style="width: 320px">
                        <el-input v-model="updateorganizationForm.admin"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="登录密码" prop="password">
                    <div style="width: 320px">
                        <el-input v-model="updateorganizationForm.password"></el-input>
                    </div>
                </el-form-item> -->
                <el-form-item label="组织名称" prop="organization_name">
                    <div style="width: 320px">
                        <el-input v-model="updateorganizationForm.organization_name"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="组织类型" prop="organization_type">
                    <div style="width: 320px">
                        <el-input v-model="updateorganizationForm.organization_type"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="组织联系人" prop="organization_Contacts">
                    <div style="width: 320px">
                        <el-input v-model="updateorganizationForm.organization_Contacts"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="组织联系电话" prop="organization_tel">
                    <div style="width: 320px">
                        <el-input v-model="updateorganizationForm.organization_tel"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="组织性质" prop="organization_objective">
                    <div style="width: 320px">
                        <el-input v-model="updateorganizationForm.organization_objective"></el-input>
                    </div>
                </el-form-item>
               <!-- <el-form-item label="失败原因" prop="reason">
                    <div style="width: 320px">
                        <el-input v-model="updateorganizationForm.reason"></el-input>
                    </div>
                </el-form-item>-->
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="updateorganizationVisible = false">取 消</el-button>
                <el-button type="primary" @click="yes1">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>


    export default {

        name: 'test',

        data() {
            return {
                activeName: 'first',
                createorganizationVisible:false,//创建志愿组织弹出框
                organizationForm:{},//创建志愿组织表单
                updateorganizationVisible:false,//修改组织框
                updateorganizationForm:{},//修改组织表单
                upid:'',
                tableData: [],
                pageNo: 1,
                pageSize: 10,
                totalRecord: 0,
                totalPage: 0,
                dialogFormVisible: false, //创建弹出框
                dialogFormVisibleEdit:false, //修改弹出框
                form:{},  //创建按钮的表单
                //创建表单
                ruleForm: {
                    title: '',
                    content: '',
                },
                //修改表单
                ruleFormEdit:{
                    title: '',
                    content: '',
                },
                //验证
                rules: {
                    title: [
                        { required: true, message: '请输入标题', trigger: 'blur' }
                    ],
                    content: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                },
                //修改验证
                rulesEdit: {
                    title: [
                        { required: true, message: '请输入标题', trigger: 'blur' }
                    ],
                    content: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                },
                formLabelWidth: '120px',
                cid:''
            }
        },

        props: {},

        components: {},

        computed: {},

        methods: {
            // 初始化
            async init() {
                const res = await this.$http('selectvolunteerlist',{
                    state:'0',
                    pageNo: this.pageNo,
                    pageSize: this.pageSize
                })
                this.tableData = res.results
                this.totalPage = res.totalPage;
                this.totalRecord = res.totalRecord;
                console.log(res)
            },
            async handleClick(tab, event) {
                console.log('1',tab);
                if (tab.index == '0') {
                    const res = await this.$http('selectvolunteerlist',{
                        pageNo: this.pageNo,
                        pageSize: this.pageSize
                    })
                    console.log('selectvolunteerlist',res)
                    this.tableData = res.results
                    this.totalPage = res.totalPage;
                    this.totalRecord = res.totalRecord;
                }else if(tab.index == '1'){
                    const res = await this.$http('selectvolteamlist',{
                        pageNo: this.pageNo,
                        pageSize: this.pageSize
                    })
                    console.log('selectvolteamlist',res)
                    this.tableData = res.results
                    this.totalPage = res.totalPage;
                    this.totalRecord = res.totalRecord;
                }
            },
            //分页
            async handleSizeChange(val) {
                this.pageSize = val;
                this.init();
            },
            async handleCurrentChange(val) {
                this.pageNo = val;
                this.init();
            },
            //创建志愿者
            createvolunteer() {
                this.dialogFormVisible = true
                // this.ruleForm.name = ""
                // this.ruleForm.sex = ""
                // this.ruleForm.address = ""
                // this.ruleForm.birth = ""
                // this.ruleForm.outlook = ""
                // this.ruleForm.tel = ""
                // this.ruleForm.hobby = ""
                // this.ruleForm.intention = ""
                this.ruleForm = {}
            },

            //点击确定立即创建志愿者
            async sure(){
                // const userres = await this.$http('createUser', {
                //     rolelist : 'zyz',
                //     login_name: this.ruleForm.login_name,
                //     name: this.ruleForm.name,
                //     grid_id:'e7014e31-2d22-11ea-867a-0242ac110031'
                // })


                const res = await this.$http('createvolunteer',{
                    name:this.ruleForm.name,
                    // login_name: this.ruleForm.login_name,
                    sex:this.ruleForm.sex,
                    address:this.ruleForm.address,
                    birth:this.ruleForm.birth,
                    outlook:this.ruleForm.outlook,
                    tel:this.ruleForm.tel,
                    hobby:this.ruleForm.hobby,
                    intention:this.ruleForm.intention,
                    state:'0',
                })
                if (res.count === 1) {
                    this.$message({
                        message: '创建成功',
                        type: 'success'
                    });
                    this.dialogFormVisible = false
                    this.init()
                } else {
                    this.$message({
                        message: '创建失败',
                        type: 'error'
                    });
                }
            },
            //创建志愿组织
            createorganization() {
                this.createorganizationVisible = true
                // this.organizationForm.admin = ""
                // this.organizationForm.password = ""
                // this.organizationForm.organization_name = ""
                // this.organizationForm.organization_type = ""
                // this.organizationForm.organization_Contacts = ""
                // this.organizationForm.organization_tel = ""
                this.organizationForm = {}
            },
            //点击确定立即创建志愿组织
            async sure1(){
                const res = await this.$http('createvolunteer',{
                    /*admin:this.organizationForm.admin,
                    password:this.organizationForm.password,*/
                    organization_name:this.organizationForm.organization_name,
                    organization_type:this.organizationForm.organization_type,
                    organization_Contacts:this.organizationForm.organization_Contacts,
                    organization_tel:this.organizationForm.organization_tel,
                    organization_objective:this.organizationForm.organization_objective,
                    state:'1',
                })
                console.log(res,'res')
                if (res.count === 1) {
                    this.$message({
                        message: '创建成功',
                        type: 'success'
                    });
                    this.createorganizationVisible = false;
                    this.init()
                } else {
                    this.$message({
                        message: '创建失败',
                        type: 'error'
                    });
                }
            },
            //编辑
            handleEdit(row){
                console.log('编辑',row)

                this.dialogFormVisibleEdit = true
                this.cid = row.id
                this.ruleFormEdit = row
            },
            //点击确定即可完成编辑
            async yes(){
                const res = await this.$http('createvolunteer',{
                    id:this.cid,
                    name:this.ruleFormEdit.name,
                    sex:this.ruleFormEdit.sex,
                    address:this.ruleFormEdit.address,
                    birth:this.ruleFormEdit.birth,
                    outlook:this.ruleFormEdit.outlook,
                    tel:this.ruleFormEdit.tel,
                    hobby:this.ruleFormEdit.hobby,
                    intention:this.ruleFormEdit.intention,
                })
                if (res.count === 1) {
                    this.$message({
                        message: '编辑成功',
                        type: 'success'
                    });
                    this.dialogFormVisibleEdit = false
                    this.init()
                } else {
                    this.$message({
                        message: '编辑失败',
                        type: 'error'
                    });
                }
            },
            //编辑组织
            async organizationEdit(row){
                this.upid = row.id
                this.updateorganizationVisible = true
                this.updateorganizationForm = row
            },
            //点击确定即可完成编辑
            async yes1(){
                const res = await this.$http('createvolunteer',{
                    id:this.upid,
                   /* admin:this.updateorganizationForm.admin,
                    password:this.updateorganizationForm.password,*/
                    organization_name:this.updateorganizationForm.organization_name,
                    organization_type:this.updateorganizationForm.organization_type,
                    organization_Contacts:this.updateorganizationForm.organization_Contacts,
                    organization_tel:this.updateorganizationForm.organization_tel,
                    organization_objective:this.updateorganizationForm.organization_objective,
                })
                this.activeName = 'first'
                if (res.count === 1) {
                    this.$message({
                        message: '编辑成功',
                        type: 'success'
                    });
                    this.updateorganizationVisible = false
                    this.init()
                } else {
                    this.$message({
                        message: '编辑失败',
                        type: 'error'
                    });
                }

            },
            //删除
            async handleDelete(row){
                console.log('row',row)
                this.$confirm('将永久删除该数据, 是否继续?', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    const res =await this.$http('createvolunteer',{
                        id:row.id,
                        del_flag:'1'
                    })
                    this.init()
                    this.activeName = 'first'
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

            //搜索
            async query(){
                const res = await this.$http('info',{
                    title:this.form.title
                })
                this.tableData = res.results
                this.totalPage = res.totalPage;
                this.totalRecord = res.totalRecord;
            }
        },

        watch: {},

        mounted() {
            this.init();
        },

    }
</script>

<style scoped>

</style>
